<template>
	<div id="app">
		<keep-alive :include="storage ? storage : '--'">
			<router-view />
		</keep-alive>
	</div>
</template>

<script>
import { mapGetters } from 'vuex';
import { closeStreamPort } from '@/utils/api';

export default {
	name: 'App',
	data() {
		return {
			beforeUnloadTime: '',
			gapTime: ''
		};
	},
	computed: {
		...mapGetters('storageRoutes', {
			// 缓存组件的数组
			getStorage: 'getRoutes'
		}),
		storage() {
			return this.getStorage.join(',');
		}
	},
	mounted() {
		window.addEventListener('beforeunload', (e) => this.beforeunloadHandler(e));
		window.addEventListener('unload', this.updateHandler);
	},
	destroyed() {
		window.removeEventListener('beforeunload', () => this.beforeunloadHandler);
		window.removeEventListener('unload', this.updateHandler);
	},

	methods: {
		beforeunloadHandler(e) {
			e = e || window.event;
			if (e) {
				e.returnValue = '关闭提示';
			}
			return '关闭提示';
		},
		updateHandler() {
			fetch(`${window.location.origin}/cdszls/cdszlsPortLog/closeCurrentScene`, {
				method: 'GET',
				headers: { 'Content-Type': 'application/json' },
				keepalive: true
			});
		}
	}
};
</script>

<style lang="scss">
@import url(./assets/style/common.css); // 常用样式表 - xy
@import url(./assets/font/iconfont.css); // 字体样式

// 字体文件
@font-face {
	font-family: 'iconfont';
	src: url('./assets/font/iconfont.ttf?t=1653274658407') format('truetype');
}

.iconfont {
	font-family: 'iconfont' !important;
	font-size: 16px;
	font-style: normal;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}
</style>
